Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Atoms.cluster_from_file() in io.feff.inputs giving wrong number of atoms #3426

Merged
merged 51 commits into from
Nov 2, 2023

Conversation

kaifengZheng
Copy link
Contributor

Summary

Atoms.cluster_from_file() generates a cluster with a wrong number of atoms because it skips wrong lines when the format of feff input file in the Atom parts is different.
Major changes:

  • feature 1(old): skipped 3 lines from the line having "ATOMS"
  • fix 1(new): only skip 1 line(ignore ATOMS line)
  • feature 2(old): It requires the special format of FEFF input file
  • fix 2(new): add a condition to ignore the lines beginning with "*", which is feasible to adapt the different format of Atom parts

Checklist

  • Google format doc strings added. Check with ruff.
  • Type annotations included. Check with mypy.
  • Tests added for new features/fixes.
  • If applicable, new classes/functions/modules have duecredit @due.dcite decorators to reference relevant papers by DOI (example)

Tip: Install pre-commit hooks to auto-check types and linting before every commit:

pip install -U pre-commit
pre-commit install

kaifengZheng and others added 30 commits August 18, 2023 22:20
Signed-off-by: KaifengZheng <[email protected]>
Signed-off-by: KaifengZheng <[email protected]>
Signed-off-by: KaifengZheng <[email protected]>
This reverts commit 8112068.
…checks

initialize PymatgenTest.TEST_STRUCTURES as dict[Path, None]
Signed-off-by: KaifengZheng <[email protected]>
coords = []
symbols = []
for line in lines:
if line:
if line and line[0].__contains__("*"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if line and line[0].__contains__("*"):
if line and line.startswith("*"):

def test_atom_num(self):
atoms = Atoms.cluster_from_file("ATOMS_test.inp")
num_atom = 37
assert len(atoms) != num_atom
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not test for the expected number of atoms?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Janosh,
The expected number of atoms is 37; how should I specify this value?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is != a typo?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing one level of indentation to make it a method of the test class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me fix it. sorry to confuse you. I want it to pass when the expected number of atoms is equal to num_atom and throw an error when the numbers are not equal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have 6 or more existing .inp files. Can you reuse those for testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every updated feff.inp file has the same format. My input file deletes the * lines under ATOMS, which can be used for the test.
image

Signed-off-by: KaifengZheng <[email protected]>
Signed-off-by: KaifengZheng <[email protected]>
def test_atom_num(self):
atoms = Atoms.cluster_from_file("ATOMS_test.inp")
num_atom = 37
assert len(atoms) != num_atom
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing one level of indentation to make it a method of the test class.

Copy link
Member

@janosh janosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks almost done but can you fix the failing tests: FileNotFoundError: [Errno 2] No such file or directory: 'ATOMS_test.inp'?

@janosh janosh added io Input/output functionality fix Bug fix PRs labels Oct 31, 2023
@janosh janosh changed the title Fix a bug in io.feff.inputs.Atoms Fix Atoms.cluster_from_file() in io.feff.inputs giving wrong number of atoms Nov 2, 2023
@janosh janosh merged commit 8ce1cdd into materialsproject:master Nov 2, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix PRs io Input/output functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants